package gw.com.android.ui.trade.Fragment;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.gwtsz.gts2.hx.R;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import gw.com.android.app.ActivityManager;
import gw.com.android.app.AppContances;
import gw.com.android.app.AppMain;
import gw.com.android.app.GTConfig;
import gw.com.android.model.ConfigType;
import gw.com.android.model.ConfigUtil;
import gw.com.android.model.DataManager;
import gw.com.android.presenter.AdsConfigPresenter;
import gw.com.android.presenter.RewardPresenter;
import gw.com.android.terminal.GTSDataListener;
import gw.com.android.ui.MainActivity;
import gw.com.android.ui.chart.PortChartActivity;
import gw.com.android.ui.dialog.ProfitShareDialog;
import gw.com.android.ui.onlive.AutoDiscussActivity;
import gw.com.android.ui.onlive.TradeResultData;
import gw.com.android.ui.quote2.addquote.QuoteAddSelfActivity;
import gw.com.android.ui.quote2.editquote.EditOptionalActivity;
import gw.com.android.ui.trade.AdvertiseHandler;
import gw.com.android.ui.trade.RewardDialog;
import gw.com.android.utils.ColorThemeUtil;
import gw.com.android.utils.PackStatis;
import gw.com.jni.library.terminal.GTSConst;
import www.com.library.app.ObjectSessionStore;
import www.com.library.app.PushMsgTabFragment;
import www.com.library.model.DataItemDetail;
import www.com.library.util.CommonUtils;
import www.com.library.util.DoubleConverter;
import www.com.library.view.BtnClickListener;
import www.com.library.view.TintTextView;
import www.com.library.view.UISpannableStringBuilder;

/**
 * 交易成功界面
 *
 * @author Administrator
 */
public class OrderSuccessFragment extends PushMsgTabFragment implements PlatformActionListener {

    private final int REQUEST_DISCUSS = 36;
    /**
     * 顶部title,失败提示信息视图
     */
    private TextView name1, name2, name3, name4, name5, name6;
    private TextView title, content1, content2, content3, content4, content5, content6, content8, symbol;
    private View viewAmount;
    /**
     * 右边按钮布局
     */
    @BindView(R.id.btn_custom_left)
    TintTextView leftBtn;
    @BindView(R.id.btn_custom_right)
    TintTextView rightBtn;
    @BindView(R.id.iv_ad)
    ImageView ivAd;
    @BindView(R.id.res_discuss_tag)
    ImageView ivDiscussTag;
    /**
     * 界面各参数对象集
     */
    private DataItemDetail mDetail;
    /**
     * 交易类型
     */
    private String mCurTag = AppContances.TAB_ID_CREATE_ORDER;
    /**
     * 底部按钮点击监听对象
     */
    private BtnClickListener mListener;
    private AdvertiseHandler adHandler;
    private RewardDialog rewardDialog;


    @Override
    public void setArguments(Bundle args) {
        super.setArguments(args);
        if (args != null) {
            mDetail = args.getParcelable("mDetail");
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_order_result_success_new;
    }

    @Override
    protected void initLayoutView() {
        ButterKnife.bind(this, mRootView);
        title = (TextView) mRootView.findViewById(R.id.res_status_title);
        content1 = (TextView) mRootView.findViewById(R.id.res_status_content1);
        content2 = (TextView) mRootView.findViewById(R.id.res_status_content2);
        content3 = (TextView) mRootView.findViewById(R.id.res_status_content3);
        content4 = (TextView) mRootView.findViewById(R.id.res_status_content4);
        content5 = (TextView) mRootView.findViewById(R.id.res_status_content5);
        content6 = (TextView) mRootView.findViewById(R.id.res_status_content6);
        name1 = (TextView) mRootView.findViewById(R.id.res_status_name1);
        name2 = (TextView) mRootView.findViewById(R.id.res_status_name2);
        name3 = (TextView) mRootView.findViewById(R.id.res_status_name3);
        name4 = (TextView) mRootView.findViewById(R.id.res_status_name4);
        name5 = (TextView) mRootView.findViewById(R.id.res_status_name5);
        name6 = (TextView) mRootView.findViewById(R.id.res_status_name6);
        viewAmount = mRootView.findViewById(R.id.res_state_amount);
        content8 = (TextView) mRootView.findViewById(R.id.res_status_content8);
        symbol = (TextView) mRootView.findViewById(R.id.res_status_symbol);
        Typeface typeface = Typeface.createFromAsset(getResources().getAssets(), "fonts/DIN_Medium.ttf");
        content8.setTypeface(typeface);
        symbol.setTypeface(typeface);
    }

    @Override
    protected void initViewData() {
        mDetail.Dump();
        mCurTag = mDetail.getString("mCurrentTag");
        ivDiscussTag.setVisibility(View.GONE);
        content3.setVisibility(View.GONE);
        content4.setVisibility(View.GONE);
        content5.setVisibility(View.GONE);
        content6.setVisibility(View.GONE);
        name3.setVisibility(View.GONE);
        name4.setVisibility(View.GONE);
        name5.setVisibility(View.GONE);
        name6.setVisibility(View.GONE);
        viewAmount.setVisibility(View.GONE);
        String str = "";
        String operateName = "";
        //市价开仓
        if (mCurTag.equals(AppContances.TAB_ID_CREATE_ORDER)) {
            operateName = AppMain.getAppString(R.string.order_type_create_market);
            leftBtn.setText(AppMain.getAppString(R.string.order_result_order_continue));
            rightBtn.setText(AppMain.getAppString(R.string.order_result_to_order));
            handleAd(AdsConfigPresenter.TYPE_CREATE_ORDER_SUCCESS, false);
            //挂单开仓
        } else if (mCurTag.equals(AppContances.TAB_ID_PENDING_ORDER)) {
            operateName = AppMain.getAppString(R.string.order_type_create_pending);
            leftBtn.setText(AppMain.getAppString(R.string.order_result_order_continue));
            rightBtn.setText(AppMain.getAppString(R.string.order_result_to_pending));
            //市价平仓
        } else if (mCurTag.equals(AppContances.TAB_ID_CLOSE_ORDER)) {
            operateName = AppMain.getAppString(R.string.order_type_close_market);
            leftBtn.setText(AppMain.getAppString(R.string.order_result_to_order));
            rightBtn.setText(AppMain.getAppString(R.string.order_result_profit));
//            if (GTConfig.instance().getAccountType() == GTConfig.ACC_TYPE_REAL) {
//                // 真实用户  查看持仓的入口修改为一键晒单
//                ivDiscussTag.setVisibility(View.VISIBLE);
//                leftBtn.setText(AppMain.getAppString(R.string.discuss_auto_title));
//            }
            double profit = DoubleConverter.add(Double.valueOf(mDetail.getString(GTSConst.JSON_KEY_PROFIT)), Double.valueOf(mDetail.getString(GTSConst.JSON_KEY_INTEREST)));
            int profitState = DoubleConverter.addResult(profit);
            boolean isProfit = profitState == 1;
            if (isProfit) {
                handleAd(AdsConfigPresenter.TYPE_CLOSE_ORDER_PROFIT, true);
            } else {
                handleAd(AdsConfigPresenter.TYPE_CLOSE_ORDER_SUCCESS, false);
            }
            //挂单修改
        } else if (mCurTag.equals(AppContances.TAB_ID_PENDING_MODIFY_ORDER)) {
            operateName = AppMain.getAppString(R.string.order_type_pending_modity);
            rightBtn.setText(AppMain.getAppString(R.string.order_result_to_pending));
            leftBtn.setVisibility(View.GONE);
            //止盈止损修改
        } else if (mCurTag.equals(AppContances.TAB_ID_MODIFY_ORDER)) {
            operateName = AppMain.getAppString(R.string.order_type_modify_market);
            rightBtn.setText(AppMain.getAppString(R.string.order_result_to_order));
            leftBtn.setVisibility(View.GONE);
        }
        title.setText(AppMain.getAppString(R.string.order_result_success, operateName));

        if (mDetail.getString("mTime").length() > 0) {
            str = mDetail.getString("mTime");
        }
        String name1Text = operateName + AppMain.getAppString(R.string.order_result_name_time);
        name1.setText(name1Text);
        content1.setText(str);

        name2.setText(R.string.order_result_name_product);
        content2.setText(mDetail.getString("mSymbol"));
        //市价,挂单开仓
        if (mCurTag.equals(AppContances.TAB_ID_CREATE_ORDER) || mCurTag.equals(AppContances.TAB_ID_PENDING_ORDER)) {

            if (mCurTag.equals(AppContances.TAB_ID_CREATE_ORDER)) {
                name3.setText(AppMain.getAppString(R.string.order_type_create_market));
            } else {
                if (mDetail.getInt("mType") == AppContances.ORDER_TYPE_APPLY_TYPE) {
                    name3.setText(AppMain.getAppString(R.string.order_type_create_limit_pending));
                } else {
                    name3.setText(AppMain.getAppString(R.string.order_type_create_stop_pending));
                }
            }
            content3.setText(getCutAndPrice());
            name3.setVisibility(View.VISIBLE);
            content3.setVisibility(View.VISIBLE);

            name4.setText(AppMain.getAppString(R.string.order_result_order_id));
            content4.setText("#" + String.valueOf(mDetail.getInt("mOrderID")));
            name4.setVisibility(View.VISIBLE);
            content4.setVisibility(View.VISIBLE);

            if (mDetail.getString("mLoss").length() > 0) {
                name5.setText(AppMain.getAppString(R.string.order_result_title_loss));
                content5.setText(mDetail.getString("mLoss"));
                name5.setVisibility(View.VISIBLE);
                content5.setVisibility(View.VISIBLE);
            }

            if (mDetail.getString("mWin").length() > 0) {
                name6.setText(AppMain.getAppString(R.string.order_result_title_profit));
                content6.setText(mDetail.getString("mWin"));
                name6.setVisibility(View.VISIBLE);
                content6.setVisibility(View.VISIBLE);
            }
            //修改止损止盈
        } else if (mCurTag.equals(AppContances.TAB_ID_MODIFY_ORDER)) {

            if (mDetail.getString("mLoss").length() > 0) {
                if (!mDetail.getString("mLoss").equals(mDetail.getString("mPreLoss"))) {
                    name3.setText(R.string.order_result_title_loss);
                    content3.setText(mDetail.getString("mLoss"));
                    name3.setVisibility(View.VISIBLE);
                    content3.setVisibility(View.VISIBLE);
                }
            } else {
                if (mDetail.getString("mPreLoss").length() > 0) {
                    name3.setText(AppMain.getAppString(R.string.order_result_cancel_loss));
                    name3.setVisibility(View.VISIBLE);
                }
            }

            if (mDetail.getString("mWin").length() > 0) {
                if (!mDetail.getString("mWin").equals(mDetail.getString("mPreWin"))) {
                    name4.setText(AppMain.getAppString(R.string.order_result_title_profit));
                    content4.setText(mDetail.getString("mWin"));
                    name4.setVisibility(View.VISIBLE);
                    content4.setVisibility(View.VISIBLE);
                }
            } else {
                if (mDetail.getString("mPreWin").length() > 0) {
                    name4.setText(AppMain.getAppString(R.string.order_result_cancel_profit));
                    name4.setVisibility(View.VISIBLE);
                }
            }
            //市价平仓
        } else if (mCurTag.equals(AppContances.TAB_ID_CLOSE_ORDER)) {

            name3.setText(AppMain.getAppString(R.string.order_type_close_market_title));
            content3.setText(getCutAndPrice());
            name3.setVisibility(View.VISIBLE);
            content3.setVisibility(View.VISIBLE);

            name4.setText(AppMain.getAppString(R.string.order_result_ping_id));
            content4.setText("#" + String.valueOf(mDetail.getInt("mOrderID")));
            name4.setVisibility(View.VISIBLE);
            content4.setVisibility(View.VISIBLE);
            double profit = DoubleConverter.add(Double.valueOf(mDetail.getString(GTSConst.JSON_KEY_PROFIT)), Double.valueOf(mDetail.getString(GTSConst.JSON_KEY_INTEREST)));
            int profitState = DoubleConverter.addResult(profit);
            viewAmount.setVisibility(View.VISIBLE);
            content8.setText(DoubleConverter.to2Decimal(Math.abs(profit)));
            ColorThemeUtil.instance().setPriceColor(content8, profitState);
            symbol.setText(profit >= 0 ? "$" : "-$");
            ColorThemeUtil.instance().setPriceColor(symbol, profitState);
            //挂单修改
        } else if (mCurTag.equals(AppContances.TAB_ID_PENDING_MODIFY_ORDER)) {
            UISpannableStringBuilder mBuilder = new UISpannableStringBuilder();

            if (!mDetail.getString("mPrePrice").equals(mDetail.getString("mPrice"))) {
                name3.setText(AppMain.getAppString(R.string.order_result_title_price));
                mBuilder.append(mDetail.getString("mPrePrice"));
                mBuilder.setImage(getActivity(), R.mipmap.a_position_pricechange);
                mBuilder.append(mDetail.getString("mPrice"));
                content3.setText(mBuilder.getBuilder());
                name3.setVisibility(View.VISIBLE);
                content3.setVisibility(View.VISIBLE);
            }

            if (!mDetail.getString("mPreLot").equals(mDetail.getString("mCurLot"))) {
                mBuilder.reset();
                name4.setText(AppMain.getAppString(R.string.order_result_title_lot));
                mBuilder.append(mDetail.getString("mPreLot"));
                mBuilder.setImage(getActivity(), R.mipmap.a_position_pricechange);
                mBuilder.append(mDetail.getString("mCurLot"));
                content4.setText(mBuilder.getBuilder());
                name4.setVisibility(View.VISIBLE);
                content4.setVisibility(View.VISIBLE);
            }

            if (!mDetail.getString("mPreLoss").equals(mDetail.getString("mLoss"))) {
                mBuilder.reset();
                name5.setText(AppMain.getAppString(R.string.order_item_title_loss));
                if (mDetail.getString("mPreLoss").length() > 0) {
                    mBuilder.append(mDetail.getString("mPreLoss"));
                } else {
                    mBuilder.append(AppMain.getAppString(R.string.order_result_title_not_set));
                }
                mBuilder.setImage(getActivity(), R.mipmap.a_position_pricechange);
                if (mDetail.getString("mLoss").length() > 0) {
                    mBuilder.append(mDetail.getString("mLoss"));
                } else {
                    mBuilder.append(AppMain.getAppString(R.string.order_result_title_cancel));
                }
                content5.setText(mBuilder.getBuilder());
                name5.setVisibility(View.VISIBLE);
                content5.setVisibility(View.VISIBLE);
            }

            if (!mDetail.getString("mPreWin").equals(mDetail.getString("mWin"))) {
                mBuilder.reset();
                name6.setText(AppMain.getAppString(R.string.order_item_title_profit));
                if (mDetail.getString("mPreWin").length() > 0) {
                    mBuilder.append(mDetail.getString("mPreWin"));
                } else {
                    mBuilder.append(AppMain.getAppString(R.string.order_result_title_not_set));
                }
                mBuilder.setImage(getActivity(), R.mipmap.a_position_pricechange);
                if (mDetail.getString("mWin").length() > 0) {
                    mBuilder.append(mDetail.getString("mWin"));
                } else {
                    mBuilder.append(AppMain.getAppString(R.string.order_result_title_cancel));
                }
                content6.setText(mBuilder.getBuilder());
                name6.setVisibility(View.VISIBLE);
                content6.setVisibility(View.VISIBLE);
            }
        }
        rewardActivity();
    }

    private void rewardActivity() {
        if (GTConfig.instance().getAccountType() != GTConfig.ACC_TYPE_REAL) {
            return;
        }
        String code = mDetail.getString("mPrdCode"); // 3289904
        if (!RewardPresenter.getInstance().validateProduct(code)) {
            return;
        }
        final int type;
        switch (mCurTag) {
            case AppContances.TAB_ID_CREATE_ORDER:
                type = RewardPresenter.OPEN;
                break;
            case AppContances.TAB_ID_CLOSE_ORDER:
                type = RewardPresenter.CLOSE;
                break;
            default:
                return;
        }
        RewardPresenter.getInstance().onConfig(new RewardPresenter.OnConfigListener() {
            @Override
            public void onConfig(boolean hasConfig, int remainOpenNum, int remainCloseNum, float minLots) {
                showRewardDialog(hasConfig, remainOpenNum, remainCloseNum, minLots, type);
            }
        }, type);
    }

    private void showRewardDialog(boolean hasConfig, int remainOpenNum, int remainCloseNum, float minLots, final int type) {
        if (hasConfig && getActivity() != null && !getActivity().isFinishing()) {
            if (type == RewardPresenter.OPEN) {
                if (remainOpenNum <= 0) {
                    return;
                }
            } else if (type == RewardPresenter.CLOSE) {
                float mCurLot;
                try {
                    mCurLot = Float.valueOf(mDetail.getString("mCurLot"));
                } catch (NumberFormatException ignore) {
                    return;
                }
                if (remainCloseNum <= 0 || mCurLot < minLots) {
                    return;
                }
            }
            rewardDialog = new RewardDialog(getActivity()).setType(type).setListener(new RewardDialog.RewardListener() {
                @Override
                public void onNext(boolean isGet) {
                    if (isGet) {
                        rewardDraw(type);
                    } else {
                        rewardDialog.dismiss();
                        if (getActivity() != null) {
                            getActivity().onBackPressed();
                        }
                    }
                }

                @Override
                public void onActivityPage() {
                    String mUrl = ConfigUtil.instance().getUrlPath("rewardActivity");
                    DataItemDetail item = new DataItemDetail();
                    item.setStringValue(ConfigType.CONFIG_TYPE_TYPE_URL_TAG, mUrl);
                    ActivityManager.showWebPageActivity(getActivity(), item, null);
                }
            });
            rewardDialog.setOnDissmissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    rewardDialog.setListener(null);
                    rewardDialog = null;
                }
            });
            rewardDialog.show();
        }
        RewardPresenter.getInstance().addShowed(type);
    }

    private void rewardDraw(final int type) {
        RewardPresenter.OnGetRewardListener listener = new RewardPresenter.OnGetRewardListener() {
            @Override
            public void onSuccess(String money, int remainOpenNum, int remainCloseNum) {
                rewardSuccess(money, remainOpenNum, remainCloseNum, type);
            }

            @Override
            public void onFailure(Exception e) {
                rewardException(e);
            }
        };
        String mTime = mDetail.getString("mTime");
        if (type == RewardPresenter.OPEN) {
            DataItemDetail item = DataManager.instance().getOpenDealModel(mDetail.getInt("mOrderID"));
            String mId = item == null ? "" : item.getString(GTSConst.JSON_KEY_ORDERID);
            RewardPresenter.getInstance().getOpenAward(mId, mTime, listener);
        } else if (type == RewardPresenter.CLOSE) {
            DataItemDetail item = DataManager.instance().getCloseDealModel(mDetail.getInt("mOrderID"));
            String mId = item == null ? "" : item.getString(GTSConst.JSON_KEY_ORDERID);
            RewardPresenter.getInstance().getCloseAward(mId, mTime, listener);
        }
    }

    private void rewardSuccess(String money, int remainOpenNum, int remainCloseNum, int type) {
        if (rewardDialog != null && getActivity() != null && !getActivity().isFinishing()) {
            rewardDialog.onRewardSuccess(money, remainOpenNum, remainCloseNum, type);
        }
    }

    private void rewardException(Exception e) {
        if (rewardDialog != null && getActivity() != null && !getActivity().isFinishing()) {
            rewardDialog.onException(e);
        }
    }

    private void handleAd(String tag, boolean profit) {
        if (adHandler == null) {
            adHandler = new AdvertiseHandler(tag);
        }
        if (profit) {
            // 如果有平仓盈利广告，优化显示盈利广告，否则显示平仓成功广告
            if (adHandler.isEnable()) {
                double profitAmount = DoubleConverter.add(Double.valueOf(mDetail.getString(GTSConst.JSON_KEY_PROFIT)), Double.valueOf(mDetail.getString(GTSConst.JSON_KEY_INTEREST)));
                adHandler.handleProfit(getActivity(), ivAd, profitAmount, this);
            } else {
                adHandler = new AdvertiseHandler(AdsConfigPresenter.TYPE_CLOSE_ORDER_SUCCESS);
                adHandler.handle(getActivity(), ivAd);
            }
        } else {
            adHandler.handle(getActivity(), ivAd);
        }
    }

    /**
     * 返回买卖方向，手数，产品名和价格
     */
    private String getCutAndPrice() {
        String str = getDirection() + AppMain.getAppString(R.string.order_trade_lot, mDetail.getString("mCurLot"));
        str += "@" + mDetail.getString("mPrice");
        return str;
    }

    /**
     * 设置按钮点击监听事件
     */
    public void setSucClickListener(BtnClickListener listener) {
        mListener = listener;
    }

    public String getDirection() {
        //0为买入，1为卖出
        if (mDetail.getInt("mTradeDir") == AppContances.TRADE_TYPE_BUY) {
            return AppMain.getAppString(R.string.order_trade_type_buy);
        } else {
            return AppMain.getAppString(R.string.order_trade_type_sale);
        }
    }

    private void autoDiscuss() {
        PackStatis.getToService("clickNowBask", "Trade", null, null);
        double profit = DoubleConverter.add(Double.valueOf(mDetail.getString(GTSConst.JSON_KEY_PROFIT)), Double.valueOf(mDetail.getString(GTSConst.JSON_KEY_INTEREST)));
        TradeResultData data = new TradeResultData();
        data.profit = profit >= 0;
        data.amount = DoubleConverter.to2Decimal(Math.abs(profit));
        data.product = mDetail.getString("mSymbol");
        data.quantity = mDetail.getString("mCurLot");
        data.tradeDir = mDetail.getInt("mTradeDir");
        data.openPrice = mDetail.getString("mOpenPrice");
        data.closePrice = mDetail.getString("mPrice");
        data.openTime = mDetail.getString("mOpenTime");
        data.closeTime = mDetail.getString("mTime");
        startActivityForResult(new Intent(getContext(), AutoDiscussActivity.class).putExtra("tradeResult", data), REQUEST_DISCUSS);
    }

    /**
     * 左边按钮点击事件
     */
    @OnClick(R.id.btn_custom_left)
    void onLeftClick() {
        if (CommonUtils.isFastDoubleClick()) {
            return;
        }
//        if (GTConfig.instance().getAccountType() == GTConfig.ACC_TYPE_REAL && mCurTag.equals(AppContances.TAB_ID_CLOSE_ORDER)) {
//            // 真实用户进入 一键晒单
//            autoDiscuss();
//            return;
//        }
        PackStatis.getToService("clickContinue", "Trade", null, null);
        // 市价开仓,挂单,继续交易,市价平仓，止盈止损修改，挂单修改，返回上级界面
        if (null != mListener) {
            mListener.onBtnClick(R.id.btn_custom_left);
        } else {
            if (mCurTag.equals(AppContances.TAB_ID_CLOSE_ORDER)) {
                MainActivity mainActivity = (MainActivity) ObjectSessionStore.getObject(MainActivity.class.getSimpleName() + GTSDataListener.mainNum);
                if (null != mainActivity) {
                    mainActivity.setTabFragment(ConfigType.TAB_TRADE_TAG, ConfigType.TAB_POSITION_TYPE);
                }
            }
            if (null != getActivity()) {
                getActivity().setResult(AppContances.RESULT_CODE);
                getActivity().onBackPressed();
            }
        }
    }

    private void finishChartActivity() {
        PortChartActivity activity = (PortChartActivity) ObjectSessionStore.getObject(PortChartActivity.class.getSimpleName() + GTSDataListener.chartNum);
        if (activity != null)
            activity.finish();
    }

    private void finishQuoteAddSelfActivity() {
        QuoteAddSelfActivity activity = (QuoteAddSelfActivity) ObjectSessionStore.getObject(QuoteAddSelfActivity.class.getSimpleName());
        if (activity != null)
            activity.finish();
    }

    private void finishQuoteEditOptionalActivity() {
        EditOptionalActivity activity = (EditOptionalActivity) ObjectSessionStore.getObject(EditOptionalActivity.class.getSimpleName());
        if (activity != null)
            activity.finish();
    }

    /**
     * 右边按钮点击事件
     */
    @OnClick(R.id.btn_custom_right)
    void onRightClick() {
        if (CommonUtils.isFastDoubleClick()) {
            return;
        }
        MainActivity mainActivity = (MainActivity) ObjectSessionStore.getObject(MainActivity.class.getSimpleName() + GTSDataListener.mainNum);
        // 市价开仓，进入查看持仓
        if (mCurTag.equals(AppContances.TAB_ID_CREATE_ORDER)) {
            PackStatis.getToService("clickPosition", "Trade", null, null);
            if (null != mainActivity) {
                finishChartActivity();
                finishQuoteAddSelfActivity();
                finishQuoteEditOptionalActivity();
                mainActivity.setTabFragment(ConfigType.TAB_TRADE_TAG, ConfigType.TAB_POSITION_TYPE);
            }
            // 挂单开仓，进入查看挂单
        } else if (mCurTag.equals(AppContances.TAB_ID_PENDING_ORDER)) {
            if (null != mainActivity) {
                finishChartActivity();
                finishQuoteAddSelfActivity();
                finishQuoteEditOptionalActivity();
                mainActivity.setTabFragment(ConfigType.TAB_TRADE_TAG, ConfigType.TAB_PENDING_TYPE);
            }
            // 市价平仓,进入查看盈亏，持仓中的当日盈亏
        } else if (mCurTag.equals(AppContances.TAB_ID_CLOSE_ORDER)) {
            PackStatis.getToService("clickprofit", "Trade", null, null);
            if (null != mainActivity) {
                mainActivity.setTabFragment(ConfigType.TAB_TRADE_TAG, ConfigType.TAB_PROFIT_TYPE);
            }
            // 设置止损止盈,进入查看持仓
        } else if (mCurTag.equals(AppContances.TAB_ID_MODIFY_ORDER)) {
            PackStatis.getToService("clickPosition", "Trade", null, null);
            if (null != mainActivity) {
                mainActivity.setTabFragment(ConfigType.TAB_TRADE_TAG, ConfigType.TAB_POSITION_TYPE);
            }
        }
        if (null != getActivity()) {
            getActivity().setResult(AppContances.RESULT_CODE);
            getActivity().onBackPressed();
        }
    }

    @OnClick(R.id.res_complete)
    void onComplete(View view) {
        getActivity().onBackPressed();
        PackStatis.getToService("clickDone", "Trade", null, null);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_DISCUSS && resultCode == Activity.RESULT_OK) {
            leftBtn.setVisibility(View.GONE);
            ivDiscussTag.setVisibility(View.GONE);
            rightBtn.setBackgroundResource(R.drawable.common_big_btn_bg);
            rightBtn.setColorValue(getResources().getColor(R.color.color_e), getResources().getColor(R.color.color_e));
        }
    }

    @Override
    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
        new ProfitShareDialog(getActivity()).show();
    }

    @Override
    public void onError(Platform platform, int i, Throwable throwable) {
    }

    @Override
    public void onCancel(Platform platform, int i) {
    }

}
